<template>
  <div :class="goodsClass">
    <div class="head">
      <div class="name">
        <van-image :src="item.headPic" />{{ item.nickName }}
      </div>
      <div class="status">
        {{ item.status | formatStatus }}
      </div>
    </div>
    <div class="goods-content">
      <van-image fit="cover" :src="item.url" />
      <div class="info">
        <div class="name">{{ item.goodsName }}</div>
        <div class="price">
          {{ item.amount | formatFront
          }}<span class="decimal">{{ item.amount | formatAfter }}</span>
          <span class="company">元宝</span>
          <span class="number">×{{ item.num }}</span>
        </div>
      </div>
    </div>
    <div class="goodsFooter" v-if="button">
      <template>
        <!-- <div
          class="button"
          @click.stop="to_router('goodsDetails', { goodsId: item.goodsId })"
          v-if="item.status !== '0'"
        >
          再次兑换
        </div> -->
        <footer-button :item="item" @load="$emit('load')" @Pay="$emit('showPay',item.orderNo)"></footer-button>
      </template>
    </div>
  </div>
</template>
<script>
import { Image as VanImage } from "vant";
import { formatFront, formatAfter } from "@/utils/formatPrice";
import { statusList } from "./statusList";
import footerButton from "./footer-button";
export default {
  props: {
    item: {
      type: Object,
    },
    button: {
      type: Boolean,
      default: false,
    },
    goodsClass: {
      type: String,
      default: "goods",
    },
  },
  components: {
    [VanImage.name]: VanImage,
    footerButton,
  },
  filters: {
    formatFront(text) {
      return formatFront(text);
    },
    formatAfter(text) {
      return formatAfter(text);
    },
    formatStatus(statusId) {
      var status = statusList().find((item) => item.status === statusId);
      if (status) {
        return status.message;
      }
    },
  },
  methods: {
    to_router(name, query) {
      this.$router.push({
        name: name,
        query,
      });
    },
  },
};
</script>
<style lang="less" scoped>
.goods {
  padding-top: 13px;
  box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  padding: 0 10px 10px 10px;
}
.head {
  padding: 13px 0 15px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .name {
    display: flex;
    align-items: center;
    height: 22px;
    font-size: 14px;
    font-weight: 500;
    color: #333333;
    line-height: 22px;
    .van-image {
      flex: 22px 0 0;
      margin-right: 6px;
      width: 22px;
      height: 22px;
      border-radius: 50%;
      overflow: hidden;
    }
  }
  .status {
    color: #f34a38;
    font-size: 11px;
  }
}
.goods-content {
  display: flex;
  .van-image {
    flex: 80px 0 0;
    width: 80px;
    height: 80px;
    margin-right: 10px;
    border-radius: 4px;
  }
  .info {
    flex: 1;
    position: relative;
    .name {
      height: 36px;
      font-size: 14px;
      font-weight: 400;
      color: #333333;
      line-height: 18px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .price {
      margin-top: 29px;
      height: 18px;
      font-size: 18px;
      font-weight: bold;
      color: #333333;
      line-height: 18px;
      .decimal {
        height: 12px;
        font-size: 12px;
        line-height: 12px;
      }
      .company {
        margin-left: 2px;
        font-size: 12px;
        font-weight: 400;
        line-height: 12px;
      }
      .number {
        margin-left: 8px;
        height: 11px;
        font-size: 11px;
        font-weight: 400;
        color: #666666;
        line-height: 11px;
      }
    }
  }
}
.goodsFooter {
  margin-top: 17px;
  display: flex;
  justify-content: flex-end;
  /deep/ .button {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 15px;
    width: 68px;
    height: 28px;
    font-size: 12px;
    font-weight: 400;
    color: #333333;
    text-align: center;
    border-radius: 14px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    &.orange {
      border: 1px solid #eb5545;
      color: #eb5545;
    }
  }
}
</style>